<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>原料仓库管理系统</title>
</head>
<?php
session_start();
if ($_SESSION['username']!=null){
	
}else{
	 echo"<script type='text/javascript'>location='CKGL-index.php';
			</script>";
}
?>

<link rel="stylesheet" type="text/css" href="css/ckgl_rbb.css" />
<?php 
require('lianjie.php');
?>

<script>

</script>

<body>
<a href="CKGL_no1.php" style="text-decoration:none;">返回首页</a>
<form action="CKGL_rbb.php" method="post" id="f1">
  <table align="center">
<tr>
<td>日报表生成类型：</td>
<td><input type="date" name="ti" value="<?php echo date('Y-m-d')?>" /></td>
<td align="center"><select name="rbb_xz">
    <option value="rkb" selected>原料库日入库明细报表</option>
    <option value="ckb">原料库日出库明细报表</option>
    <option value="zhz">总汇总.可处理原料及尾料报表</option>
    <option value="hz1">汇总1.可处理钴原料</option>
    <option value="hz2">汇总2.可处理镍原料</option>
    <option value="hz3">汇总3.可处理锰原料</option>
    <option value="hz4">汇总4.可处理生产尾料</option>
    </select></td>
<td><input type="submit" name="sub" value="确定" /></td>
</tr>
</table>
</form>

<form action="CKGL_rbb.php" method="post" id="f2">
<table align="center">
<tr>
<td>周报表以及十天报表生成类型：</td>
<td><input type="date" name="ti1" value="<?php echo date('Y-m-d',strtotime('-10 day'))?>" />~~<input type="date" name="ti2" value="<?php echo date('Y-m-d')?>" /></td>
<td align="center"><select name="zsbb_xz">
    <option value="zb" selected>周报</option>
    <option value="srkb">原料库十天入库明细报表</option>
    <option value="sckb">原料库十天出库明细报表</option>
    </select></td>
<td><input type="submit" name="sub" value="确定" /></td>
</tr>
</table>
</form>
<form action="CKGL_rbb.php" method="post" id="f3">
<table align="center">
<tr>
<td>月报表生成类型：</td>
<td><input type="date" name="ti1" value="<?php echo date('Y-m-d',strtotime('-1 month'))?>" />~~~<input type="date" name="ti2" value="<?php echo date('Y-m-d')?>" /></td>
<td align="center"><select name="ybb_xz">
    <option value="ypdb" selected>原料仓库月盘点报表</option>
    <option value="ycrb">原料库出入库月报表</option>
    <option value="ycrhz">原料仓库出入库月度汇总表</option>
    <option value="bhgpyb_m">不合格品出入库月报表(分名称)</option>
    <option value="bhgpyb_b">不合格品出入库月报表(分部门)</option>
    <option value="dcyb">电池原料及产物月报表</option>
    <option value="lwryyb">绿钨百富溶液出入库月报表</option>
    <option value="wlyb">生产尾料出入库月报表</option>
    </select></td>
<td><input type="submit" name="sub" value="确定" /></td>
</tr>
</table>
</form><!---->
<div class="box">
<table  align="left" width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000">
<?php
$dates=array();
$sum=0;
$url1='';
if(isset($_POST['rbb_xz'])){
	$LB=$_POST['rbb_xz'];
	$ti=$_POST['ti'];
	if($LB=='rkb'){
		$sql="select LY,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),LBLB,concat('当日入库') from rkb where dh_date='".$ti."' group by LY,name,LBLB;";
		$sqly="select LY,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),LBLB,concat('当月累计入库') from rkb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' group by LY,name,LBLB;";
		$sum=9;
		//echo $sqly;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sql);
			$resulty=mysqli_query($connID,$sqly);
			?>
            <td style="color:#F00; background-color:#FF0;">原料库日入库明细报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日入库</td>
            </tr>
            <tr>
                <td>来源</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
                <td>大类别</td>
            </tr>
            <?php
			$SWsum=0;
			$GUsum=0;
			$NIEsum=0;
			$MENGsum=0;
			$TONGsum=0;
			$LIsum=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                <td><?php echo $myrow[8]?></td>
                </tr>
                <?php
				$SWsum=$SWsum+$myrow[2];
				$GUsum=$GUsum+$myrow[3];
				$NIEsum=$NIEsum+$myrow[4];
				$MENGsum=$MENGsum+$myrow[5];
				$TONGsum=$TONGsum+$myrow[6];
				$LIsum=$LIsum+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum;?></td>
            <td><?php echo $GUsum;?></td>
            <td><?php echo $NIEsum;?></td>
            <td><?php echo $MENGsum;?></td>
            <td><?php echo $TONGsum;?></td>
            <td><?php echo $LIsum;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月入库累计</td>
            </tr>
            <tr>
                <td>来源</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
                <td>大类别</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'15',2=>'原料库日入库明细报表',3=>'来源',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>'大类别',12=>'  ',13=>"".$sql."",14=>"".$sqly."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum1=0;
			$GUsum1=0;
			$NIEsum1=0;
			$MENGsum1=0;
			$TONGsum1=0;
			$LIsum1=0;
			while($myrowy=mysqli_fetch_array($resulty)){
				?>
                <tr>
				<td><?php echo $myrowy[0]?></td>
                <td><?php echo $myrowy[1]?></td>
                <td><?php echo $myrowy[2]?></td>
                <td><?php echo $myrowy[3]?></td>
                <td><?php echo $myrowy[4]?></td>
                <td><?php echo $myrowy[5]?></td>
                <td><?php echo $myrowy[6]?></td>
                <td><?php echo $myrowy[7]?></td>
                <td><?php echo $myrowy[8]?></td>
				</tr>
				<?php
				$SWsum1=$SWsum1+$myrowy[2];
				$GUsum1=$GUsum1+$myrowy[3];
				$NIEsum1=$NIEsum1+$myrowy[4];
				$MENGsum1=$MENGsum1+$myrowy[5];
				$TONGsum1=$TONGsum1+$myrowy[6];
				$LIsum1=$LIsum1+$myrowy[7];
            }
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum1;?></td>
            <td><?php echo $GUsum1;?></td>
            <td><?php echo $NIEsum1;?></td>
            <td><?php echo $MENGsum1;?></td>
            <td><?php echo $TONGsum1;?></td>
            <td><?php echo $LIsum1;?></td>
            </tr>
            <?php
		}
	}
	else if($LB=='ckb'){
		$sql="select BLB,QX,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),LBLB,concat('当日出库') from ckb where dh_date='".$ti."' group by QX,name,LBLB,BLB;";
		$sqly="select BLB,QX,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),LBLB,concat('当月累计出库') from ckb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' group by QX,name,LBLB,BLB;";
		//echo $sql.$sqly;
		$sum=10;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sql);
			$resulty=mysqli_query($connID,$sqly);
			?>
            <td style="color:#F00; background-color:#FF0;">原料库日出库明细报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日出库</td>
            </tr>
            <tr>
            	<td>类别</td>
                <td>去向</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
                <td>大类别</td>
            </tr>
            <?php
			$SWsum=0;
			$GUsum=0;
			$NIEsum=0;
			$MENGsum=0;
			$TONGsum=0;
			$LIsum=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                <td><?php echo $myrow[8]?></td>
                <td><?php echo $myrow[9]?></td>
                </tr>
                <?php
				$SWsum=$SWsum+$myrow[3];
				$GUsum=$GUsum+$myrow[4];
				$NIEsum=$NIEsum+$myrow[5];
				$MENGsum=$MENGsum+$myrow[6];
				$TONGsum=$TONGsum+$myrow[7];
				$LIsum=$LIsum+$myrow[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum;?></td>
            <td><?php echo $GUsum;?></td>
            <td><?php echo $NIEsum;?></td>
            <td><?php echo $MENGsum;?></td>
            <td><?php echo $TONGsum;?></td>
            <td><?php echo $LIsum;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月出库累计</td>
            </tr>
            <tr>
            	<td>类别</td>
                <td>去向</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
                <td>大类别</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'16',2=>'原料库日出库明细报表',3=>'类别',4=>'去向',5=>'名称',6=>'实物量',7=>'钴',8=>'镍',9=>'锰',10=>'铜',11=>'锂',12=>'大类别',13=>"  ",14=>"".$sql."",15=>"".$sqly."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum1=0;
			$GUsum1=0;
			$NIEsum1=0;
			$MENGsum1=0;
			$TONGsum1=0;
			$LIsum1=0;
			while($myrowy=mysqli_fetch_array($resulty)){
				?>
                <tr>
				<td><?php echo $myrowy[0]?></td>
                <td><?php echo $myrowy[1]?></td>
                <td><?php echo $myrowy[2]?></td>
                <td><?php echo $myrowy[3]?></td>
                <td><?php echo $myrowy[4]?></td>
                <td><?php echo $myrowy[5]?></td>
                <td><?php echo $myrowy[6]?></td>
                <td><?php echo $myrowy[7]?></td>
                <td><?php echo $myrowy[8]?></td>
				<td><?php echo $myrowy[9]?></td>
                </tr>
				<?php
				$SWsum1=$SWsum1+$myrowy[3];
				$GUsum1=$GUsum1+$myrowy[4];
				$NIEsum1=$NIEsum1+$myrowy[5];
				$MENGsum1=$MENGsum1+$myrowy[6];
				$TONGsum1=$TONGsum1+$myrowy[7];
				$LIsum1=$LIsum1+$myrowy[8];
            }
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum1;?></td>
            <td><?php echo $GUsum1;?></td>
            <td><?php echo $NIEsum1;?></td>
            <td><?php echo $MENGsum1;?></td>
            <td><?php echo $TONGsum1;?></td>
            <td><?php echo $LIsum1;?></td>
            </tr>
            <?php
		}
	}
	else if($LB=='zhz'){
		$sqlr="select YLLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日入库') from rkb where dh_date='".$ti."' group by YLLB;";
		$sqlyr="select YLLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计入库') from rkb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' group by YLLB;";
		$sqlc="select YLLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日出库') from ckb where dh_date='".$ti."' group by YLLB;";
		$sqlyc="select YLLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计出库') from ckb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' group by YLLB;";
		$sqljc="select r.YLLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti."' group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where r.dh_date<='".$ti."' group by r.YLLB;";
		$sum=7;
		//echo $sqljc;
		if(mysqli_select_db($connID,$dbName)){
			$resultr=mysqli_query($connID,$sqlr);
			$resultyr=mysqli_query($connID,$sqlyr);
			$resultc=mysqli_query($connID,$sqlc);
			$resultyc=mysqli_query($connID,$sqlyc);
			$resultjc=mysqli_query($connID,$sqljc);
			?>
            <td style="color:#F00; background-color:#FF0;">总汇总.可处理原料及尾料</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日入库</td>
            </tr>
            <tr>
            	<td>进销存</td>
            	<td>原料类别</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum=0;
			$GUsum=0;
			$NIEsum=0;
			$MENGsum=0;
			$TONGsum=0;
			$LIsum=0;
			while($myrowr=mysqli_fetch_array($resultr)){
				?>
                <tr>
                <td>入库</td>
                <td><?php echo $myrowr[0]?></td>
                <td><?php echo $myrowr[1]?></td>
                <td><?php echo $myrowr[2]?></td>
                <td><?php echo $myrowr[3]?></td>
                <td><?php echo $myrowr[4]?></td>
                <td><?php echo $myrowr[5]?></td>
                <td><?php echo $myrowr[6]?></td>
                </tr>
                <?php
				$SWsum=$SWsum+$myrowr[1];
				$GUsum=$GUsum+$myrowr[2];
				$NIEsum=$NIEsum+$myrowr[3];
				$MENGsum=$MENGsum+$myrowr[4];
				$TONGsum=$TONGsum+$myrowr[5];
				$LIsum=$LIsum+$myrowr[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum;?></td>
            <td><?php echo $GUsum;?></td>
            <td><?php echo $NIEsum;?></td>
            <td><?php echo $MENGsum;?></td>
            <td><?php echo $TONGsum;?></td>
            <td><?php echo $LIsum;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月入库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'16',2=>'总汇总.可处理原料及尾料',3=>'原料类别',4=>'实物量',5=>'钴',6=>'镍',7=>'锰',8=>'铜',9=>'锂',10=>"  ",11=>"".$sqlr."",12=>"".$sqlyr."",13=>"".$sqlc."",14=>"".$sqlyc."",15=>"".$sqljc."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum1=0;
			$GUsum1=0;
			$NIEsum1=0;
			$MENGsum1=0;
			$TONGsum1=0;
			$LIsum1=0;
			while($myrowyr=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>入库</td>
				<td><?php echo $myrowyr[0]?></td>
                <td><?php echo $myrowyr[1]?></td>
                <td><?php echo $myrowyr[2]?></td>
                <td><?php echo $myrowyr[3]?></td>
                <td><?php echo $myrowyr[4]?></td>
                <td><?php echo $myrowyr[5]?></td>
                <td><?php echo $myrowyr[6]?></td>
                </tr>
				<?php
				$SWsum1=$SWsum1+$myrowyr[1];
				$GUsum1=$GUsum1+$myrowyr[2];
				$NIEsum1=$NIEsum1+$myrowyr[3];
				$MENGsum1=$MENGsum1+$myrowyr[4];
				$TONGsum1=$TONGsum1+$myrowyr[5];
				$LIsum1=$LIsum1+$myrowyr[6];
            }
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum1;?></td>
            <td><?php echo $GUsum1;?></td>
            <td><?php echo $NIEsum1;?></td>
            <td><?php echo $MENGsum1;?></td>
            <td><?php echo $TONGsum1;?></td>
            <td><?php echo $LIsum1;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">当日出库</td>
            </tr>
            <tr>
            	<td>进销存</td>
            	<td>原料类别</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum2=0;
			$GUsum2=0;
			$NIEsum2=0;
			$MENGsum2=0;
			$TONGsum2=0;
			$LIsum2=0;
			while($myrowc=mysqli_fetch_array($resultc)){
				?>
                <tr>
                <td>出库</td>
                <td><?php echo $myrowc[0]?></td>
                <td><?php echo $myrowc[1]?></td>
                <td><?php echo $myrowc[2]?></td>
                <td><?php echo $myrowc[3]?></td>
                <td><?php echo $myrowc[4]?></td>
                <td><?php echo $myrowc[5]?></td>
                <td><?php echo $myrowc[6]?></td>
                </tr>
                <?php
				$SWsum2=$SWsum2+$myrowc[1];
				$GUsum2=$GUsum2+$myrowc[2];
				$NIEsum2=$NIEsum2+$myrowc[3];
				$MENGsum2=$MENGsum2+$myrowc[4];
				$TONGsum2=$TONGsum2+$myrowc[5];
				$LIsum2=$LIsum2+$myrowc[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum2;?></td>
            <td><?php echo $GUsum2;?></td>
            <td><?php echo $NIEsum2;?></td>
            <td><?php echo $MENGsum2;?></td>
            <td><?php echo $TONGsum2;?></td>
            <td><?php echo $LIsum2;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月出库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyc=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>出库</td>
				<td><?php echo $myrowyc[0]?></td>
                <td><?php echo $myrowyc[1]?></td>
                <td><?php echo $myrowyc[2]?></td>
                <td><?php echo $myrowyc[3]?></td>
                <td><?php echo $myrowyc[4]?></td>
                <td><?php echo $myrowyc[5]?></td>
                <td><?php echo $myrowyc[6]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyc[1];
				$GUsum3=$GUsum3+$myrowyc[2];
				$NIEsum3=$NIEsum3+$myrowyc[3];
				$MENGsum3=$MENGsum3+$myrowyc[4];
				$TONGsum3=$TONGsum3+$myrowyc[5];
				$LIsum3=$LIsum3+$myrowyc[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowjc=mysqli_fetch_array($resultjc)){
				?>
                <tr>
                <td>结存</td>
				<td><?php echo $myrowjc[0]?></td>
                <td><?php echo $myrowjc[1]?></td>
                <td><?php echo $myrowjc[2]?></td>
                <td><?php echo $myrowjc[3]?></td>
                <td><?php echo $myrowjc[4]?></td>
                <td><?php echo $myrowjc[5]?></td>
                <td><?php echo $myrowjc[6]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowjc[1];
				$GUsum3=$GUsum3+$myrowjc[2];
				$NIEsum3=$NIEsum3+$myrowjc[3];
				$MENGsum3=$MENGsum3+$myrowjc[4];
				$TONGsum3=$TONGsum3+$myrowjc[5];
				$LIsum3=$LIsum3+$myrowjc[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}
	}
	else if($LB=='hz1'){
		$sqlr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日入库') from rkb where dh_date='".$ti."' and YLLB='钴原料' group by name,LBLB;";
		$sqlyr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计入库') from rkb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='钴原料' group by name,LBLB;";
		$sqlc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日出库') from ckb where dh_date='".$ti."' and YLLB='钴原料' group by name,LBLB;";
		$sqlyc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计出库') from ckb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='钴原料' group by name,LBLB;";
		$sqljc="select r.YLLB,r.name,r.LBLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti."' group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where r.YLLB='钴原料' and r.dh_date<='".$ti."' group by r.name,r.LBLB;";
		$sum=9;
		//echo $sqljc;
		if(mysqli_select_db($connID,$dbName)){
			$resultr=mysqli_query($connID,$sqlr);
			$resultyr=mysqli_query($connID,$sqlyr);
			$resultc=mysqli_query($connID,$sqlc);
			$resultyc=mysqli_query($connID,$sqlyc);
			$resultjc=mysqli_query($connID,$sqljc);
			?>
            <td style="color:#F00; background-color:#FF0;">汇总1.可处理钴原料</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日入库</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
            	<td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowr=mysqli_fetch_array($resultr)){
				?>
                <tr>
                <td>入库</td>
                <td><?php echo $myrowr[0]?></td>
                <td><?php echo $myrowr[1]?></td>
                <td><?php echo $myrowr[3]?></td>
                <td><?php echo $myrowr[4]?></td>
                <td><?php echo $myrowr[5]?></td>
                <td><?php echo $myrowr[6]?></td>
                <td><?php echo $myrowr[7]?></td>
                <td><?php echo $myrowr[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowr[3];
				$GUsum3=$GUsum3+$myrowr[4];
				$NIEsum3=$NIEsum3+$myrowr[5];
				$MENGsum3=$MENGsum3+$myrowr[6];
				$TONGsum3=$TONGsum3+$myrowr[7];
				$LIsum3=$LIsum3+$myrowr[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月入库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyr=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>入库</td>
				<td><?php echo $myrowyr[0]?></td>
                <td><?php echo $myrowyr[1]?></td>
                <td><?php echo $myrowyr[3]?></td>
                <td><?php echo $myrowyr[4]?></td>
                <td><?php echo $myrowyr[5]?></td>
                <td><?php echo $myrowyr[6]?></td>
                <td><?php echo $myrowyr[7]?></td>
                <td><?php echo $myrowyr[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyr[3];
				$GUsum3=$GUsum3+$myrowyr[4];
				$NIEsum3=$NIEsum3+$myrowyr[5];
				$MENGsum3=$MENGsum3+$myrowyr[6];
				$TONGsum3=$TONGsum3+$myrowyr[7];
				$LIsum3=$LIsum3+$myrowyr[8];
            }
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">当日出库</td>
            </tr>
            <tr>
            	<td>进销存</td>
            	<td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowc=mysqli_fetch_array($resultc)){
				?>
                <tr>
                <td>出库</td>
                <td><?php echo $myrowc[0]?></td>
                <td><?php echo $myrowc[1]?></td>
                <td><?php echo $myrowc[3]?></td>
                <td><?php echo $myrowc[4]?></td>
                <td><?php echo $myrowc[5]?></td>
                <td><?php echo $myrowc[6]?></td>
                <td><?php echo $myrowc[7]?></td>
                <td><?php echo $myrowc[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowc[3];
				$GUsum3=$GUsum3+$myrowc[4];
				$NIEsum3=$NIEsum3+$myrowc[5];
				$MENGsum3=$MENGsum3+$myrowc[6];
				$TONGsum3=$TONGsum3+$myrowc[7];
				$LIsum3=$LIsum3+$myrowc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月出库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyc=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>出库</td>
				<td><?php echo $myrowyc[0]?></td>
                <td><?php echo $myrowyc[1]?></td>
                <td><?php echo $myrowyc[3]?></td>
                <td><?php echo $myrowyc[4]?></td>
                <td><?php echo $myrowyc[5]?></td>
                <td><?php echo $myrowyc[6]?></td>
                <td><?php echo $myrowyc[7]?></td>
                <td><?php echo $myrowyc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyc[3];
				$GUsum3=$GUsum3+$myrowyc[4];
				$NIEsum3=$NIEsum3+$myrowyc[5];
				$MENGsum3=$MENGsum3+$myrowyc[6];
				$TONGsum3=$TONGsum3+$myrowyc[7];
				$LIsum3=$LIsum3+$myrowyc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'18',2=>'汇总1.可处理钴原料',3=>'原料类别',4=>'原料名称',5=>'两大类别',6=>'实物量',7=>'钴',8=>'镍',9=>'锰',10=>'铜',11=>'锂',12=>"  ",13=>"".$sqlr."",14=>"".$sqlyr."",15=>"".$sqlc."",16=>"".$sqlyc."",17=>"".$sqljc."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowjc=mysqli_fetch_array($resultjc)){
				?>
                <tr>
                <td>结存</td>
				<td><?php echo $myrowjc[0]?></td>
                <td><?php echo $myrowjc[1]?></td>
                <td><?php echo $myrowjc[3]?></td>
                <td><?php echo $myrowjc[4]?></td>
                <td><?php echo $myrowjc[5]?></td>
                <td><?php echo $myrowjc[6]?></td>
                <td><?php echo $myrowjc[7]?></td>
                <td><?php echo $myrowjc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowjc[3];
				$GUsum3=$GUsum3+$myrowjc[4];
				$NIEsum3=$NIEsum3+$myrowjc[5];
				$MENGsum3=$MENGsum3+$myrowjc[6];
				$TONGsum3=$TONGsum3+$myrowjc[7];
				$LIsum3=$LIsum3+$myrowjc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}
	}
	else if($LB=='hz2'){
		$sqlr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日入库') from rkb where dh_date='".$ti."' and YLLB='镍原料' group by name,LBLB;";
		$sqlyr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计入库') from rkb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='镍原料' group by name,LBLB;";
		$sqlc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日出库') from ckb where dh_date='".$ti."' and YLLB='镍原料' group by name,LBLB;";
		$sqlyc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计出库') from ckb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='镍原料' group by name,LBLB;";
		$sqljc="select r.YLLB,r.name,r.LBLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti."' group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where r.YLLB='镍原料' and r.dh_date<='".$ti."' group by r.name,r.LBLB;";
		$sum=9;
		//echo $sqljc;
		if(mysqli_select_db($connID,$dbName)){
			$resultr=mysqli_query($connID,$sqlr);
			$resultyr=mysqli_query($connID,$sqlyr);
			$resultc=mysqli_query($connID,$sqlc);
			$resultyc=mysqli_query($connID,$sqlyc);
			$resultjc=mysqli_query($connID,$sqljc);
			?>
            <td style="color:#F00; background-color:#FF0;">汇总2.可处理镍原料</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日入库</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
            	<td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowr=mysqli_fetch_array($resultr)){
				?>
                <tr>
                <td>入库</td>
                <td><?php echo $myrowr[0]?></td>
                <td><?php echo $myrowr[1]?></td>
                <td><?php echo $myrowr[3]?></td>
                <td><?php echo $myrowr[4]?></td>
                <td><?php echo $myrowr[5]?></td>
                <td><?php echo $myrowr[6]?></td>
                <td><?php echo $myrowr[7]?></td>
                <td><?php echo $myrowr[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowr[3];
				$GUsum3=$GUsum3+$myrowr[4];
				$NIEsum3=$NIEsum3+$myrowr[5];
				$MENGsum3=$MENGsum3+$myrowr[6];
				$TONGsum3=$TONGsum3+$myrowr[7];
				$LIsum3=$LIsum3+$myrowr[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月入库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyr=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>入库</td>
				<td><?php echo $myrowyr[0]?></td>
                <td><?php echo $myrowyr[1]?></td>
                <td><?php echo $myrowyr[3]?></td>
                <td><?php echo $myrowyr[4]?></td>
                <td><?php echo $myrowyr[5]?></td>
                <td><?php echo $myrowyr[6]?></td>
                <td><?php echo $myrowyr[7]?></td>
                <td><?php echo $myrowyr[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyr[3];
				$GUsum3=$GUsum3+$myrowyr[4];
				$NIEsum3=$NIEsum3+$myrowyr[5];
				$MENGsum3=$MENGsum3+$myrowyr[6];
				$TONGsum3=$TONGsum3+$myrowyr[7];
				$LIsum3=$LIsum3+$myrowyr[8];
            }
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">当日出库</td>
            </tr>
            <tr>
            	<td>进销存</td>
            	<td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowc=mysqli_fetch_array($resultc)){
				?>
                <tr>
                <td>出库</td>
                <td><?php echo $myrowc[0]?></td>
                <td><?php echo $myrowc[1]?></td>
                <td><?php echo $myrowc[3]?></td>
                <td><?php echo $myrowc[4]?></td>
                <td><?php echo $myrowc[5]?></td>
                <td><?php echo $myrowc[6]?></td>
                <td><?php echo $myrowc[7]?></td>
                <td><?php echo $myrowc[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowc[3];
				$GUsum3=$GUsum3+$myrowc[4];
				$NIEsum3=$NIEsum3+$myrowc[5];
				$MENGsum3=$MENGsum3+$myrowc[6];
				$TONGsum3=$TONGsum3+$myrowc[7];
				$LIsum3=$LIsum3+$myrowc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月出库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyc=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>出库</td>
				<td><?php echo $myrowyc[0]?></td>
                <td><?php echo $myrowyc[1]?></td>
                <td><?php echo $myrowyc[3]?></td>
                <td><?php echo $myrowyc[4]?></td>
                <td><?php echo $myrowyc[5]?></td>
                <td><?php echo $myrowyc[6]?></td>
                <td><?php echo $myrowyc[7]?></td>
                <td><?php echo $myrowyc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyc[3];
				$GUsum3=$GUsum3+$myrowyc[4];
				$NIEsum3=$NIEsum3+$myrowyc[5];
				$MENGsum3=$MENGsum3+$myrowyc[6];
				$TONGsum3=$TONGsum3+$myrowyc[7];
				$LIsum3=$LIsum3+$myrowyc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'18',2=>'汇总2.可处理镍原料',3=>'原料类别',4=>'原料名称',5=>'两大类别',6=>'实物量',7=>'钴',8=>'镍',9=>'锰',10=>'铜',11=>'锂',12=>"  ",13=>"".$sqlr."",14=>"".$sqlyr."",15=>"".$sqlc."",16=>"".$sqlyc."",17=>"".$sqljc."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowjc=mysqli_fetch_array($resultjc)){
				?>
                <tr>
                <td>结存</td>
				<td><?php echo $myrowjc[0]?></td>
                <td><?php echo $myrowjc[1]?></td>
                <td><?php echo $myrowjc[3]?></td>
                <td><?php echo $myrowjc[4]?></td>
                <td><?php echo $myrowjc[5]?></td>
                <td><?php echo $myrowjc[6]?></td>
                <td><?php echo $myrowjc[7]?></td>
                <td><?php echo $myrowjc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowjc[3];
				$GUsum3=$GUsum3+$myrowjc[4];
				$NIEsum3=$NIEsum3+$myrowjc[5];
				$MENGsum3=$MENGsum3+$myrowjc[6];
				$TONGsum3=$TONGsum3+$myrowjc[7];
				$LIsum3=$LIsum3+$myrowjc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}
	}
	else if($LB=='hz3'){
		$sqlr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日入库') from rkb where dh_date='".$ti."' and YLLB='锰原料' group by name,LBLB;";
		$sqlyr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计入库') from rkb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='锰原料' group by name,LBLB;";
		$sqlc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日出库') from ckb where dh_date='".$ti."' and YLLB='锰原料' group by name,LBLB;";
		$sqlyc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计出库') from ckb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='锰原料' group by name,LBLB;";
		$sqljc="select r.YLLB,r.name,r.LBLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti."' group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where r.YLLB='锰原料' and r.dh_date<='".$ti."' group by r.name,r.LBLB;";
		$sum=9;
		//echo $sqljc;
		if(mysqli_select_db($connID,$dbName)){
			$resultr=mysqli_query($connID,$sqlr);
			$resultyr=mysqli_query($connID,$sqlyr);
			$resultc=mysqli_query($connID,$sqlc);
			$resultyc=mysqli_query($connID,$sqlyc);
			$resultjc=mysqli_query($connID,$sqljc);
			?>
            <td style="color:#F00; background-color:#FF0;">汇总3.可处理锰原料</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日入库</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
            	<td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowr=mysqli_fetch_array($resultr)){
				?>
                <tr>
                <td>入库</td>
                <td><?php echo $myrowr[0]?></td>
                <td><?php echo $myrowr[1]?></td>
                <td><?php echo $myrowr[3]?></td>
                <td><?php echo $myrowr[4]?></td>
                <td><?php echo $myrowr[5]?></td>
                <td><?php echo $myrowr[6]?></td>
                <td><?php echo $myrowr[7]?></td>
                <td><?php echo $myrowr[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowr[3];
				$GUsum3=$GUsum3+$myrowr[4];
				$NIEsum3=$NIEsum3+$myrowr[5];
				$MENGsum3=$MENGsum3+$myrowr[6];
				$TONGsum3=$TONGsum3+$myrowr[7];
				$LIsum3=$LIsum3+$myrowr[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月入库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyr=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>入库</td>
				<td><?php echo $myrowyr[0]?></td>
                <td><?php echo $myrowyr[1]?></td>
                <td><?php echo $myrowyr[3]?></td>
                <td><?php echo $myrowyr[4]?></td>
                <td><?php echo $myrowyr[5]?></td>
                <td><?php echo $myrowyr[6]?></td>
                <td><?php echo $myrowyr[7]?></td>
                <td><?php echo $myrowyr[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyr[3];
				$GUsum3=$GUsum3+$myrowyr[4];
				$NIEsum3=$NIEsum3+$myrowyr[5];
				$MENGsum3=$MENGsum3+$myrowyr[6];
				$TONGsum3=$TONGsum3+$myrowyr[7];
				$LIsum3=$LIsum3+$myrowyr[8];
            }
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">当日出库</td>
            </tr>
            <tr>
            	<td>进销存</td>
            	<td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowc=mysqli_fetch_array($resultc)){
				?>
                <tr>
                <td>出库</td>
                <td><?php echo $myrowc[0]?></td>
                <td><?php echo $myrowc[1]?></td>
                <td><?php echo $myrowc[3]?></td>
                <td><?php echo $myrowc[4]?></td>
                <td><?php echo $myrowc[5]?></td>
                <td><?php echo $myrowc[6]?></td>
                <td><?php echo $myrowc[7]?></td>
                <td><?php echo $myrowc[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowc[3];
				$GUsum3=$GUsum3+$myrowc[4];
				$NIEsum3=$NIEsum3+$myrowc[5];
				$MENGsum3=$MENGsum3+$myrowc[6];
				$TONGsum3=$TONGsum3+$myrowc[7];
				$LIsum3=$LIsum3+$myrowc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月出库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyc=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>出库</td>
				<td><?php echo $myrowyc[0]?></td>
                <td><?php echo $myrowyc[1]?></td>
                <td><?php echo $myrowyc[3]?></td>
                <td><?php echo $myrowyc[4]?></td>
                <td><?php echo $myrowyc[5]?></td>
                <td><?php echo $myrowyc[6]?></td>
                <td><?php echo $myrowyc[7]?></td>
                <td><?php echo $myrowyc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyc[3];
				$GUsum3=$GUsum3+$myrowyc[4];
				$NIEsum3=$NIEsum3+$myrowyc[5];
				$MENGsum3=$MENGsum3+$myrowyc[6];
				$TONGsum3=$TONGsum3+$myrowyc[7];
				$LIsum3=$LIsum3+$myrowyc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'18',2=>'汇总3.可处理锰原料',3=>'原料类别',4=>'原料名称',5=>'两大类别',6=>'实物量',7=>'钴',8=>'镍',9=>'锰',10=>'铜',11=>'锂',12=>"  ",13=>"".$sqlr."",14=>"".$sqlyr."",15=>"".$sqlc."",16=>"".$sqlyc."",17=>"".$sqljc."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowjc=mysqli_fetch_array($resultjc)){
				?>
                <tr>
                <td>结存</td>
				<td><?php echo $myrowjc[0]?></td>
                <td><?php echo $myrowjc[1]?></td>
                <td><?php echo $myrowjc[3]?></td>
                <td><?php echo $myrowjc[4]?></td>
                <td><?php echo $myrowjc[5]?></td>
                <td><?php echo $myrowjc[6]?></td>
                <td><?php echo $myrowjc[7]?></td>
                <td><?php echo $myrowjc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowjc[3];
				$GUsum3=$GUsum3+$myrowjc[4];
				$NIEsum3=$NIEsum3+$myrowjc[5];
				$MENGsum3=$MENGsum3+$myrowjc[6];
				$TONGsum3=$TONGsum3+$myrowjc[7];
				$LIsum3=$LIsum3+$myrowjc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}
	}
	else if($LB=='hz4'){
		$sqlr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日入库') from rkb where dh_date='".$ti."' and YLLB='生产尾料' group by name,LBLB;";
		$sqlyr="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计入库') from rkb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='生产尾料' group by name,LBLB;";
		$sqlc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当日出库') from ckb where dh_date='".$ti."' and YLLB='生产尾料' group by name,LBLB;";
		$sqlyc="select YLLB,name,LBLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当月累计出库') from ckb where dh_date>='".date('Y-m',strtotime($ti))."-01' and dh_date<='".$ti."' and YLLB='生产尾料' group by name,LBLB;";
		$sqljc="select r.YLLB,r.name,r.LBLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti."' group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where r.YLLB='生产尾料' and r.dh_date<='".$ti."' group by r.name,r.LBLB;";
		$sum=9;
		//echo $sqljc;
		if(mysqli_select_db($connID,$dbName)){
			$resultr=mysqli_query($connID,$sqlr);
			$resultyr=mysqli_query($connID,$sqlyr);
			$resultc=mysqli_query($connID,$sqlc);
			$resultyc=mysqli_query($connID,$sqlyc);
			$resultjc=mysqli_query($connID,$sqljc);
			?>
            <td style="color:#F00; background-color:#FF0;">汇总4.可处理生产尾料</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当日入库</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
            	<td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowr=mysqli_fetch_array($resultr)){
				?>
                <tr>
                <td>入库</td>
                <td><?php echo $myrowr[0]?></td>
                <td><?php echo $myrowr[1]?></td>
                <td><?php echo $myrowr[3]?></td>
                <td><?php echo $myrowr[4]?></td>
                <td><?php echo $myrowr[5]?></td>
                <td><?php echo $myrowr[6]?></td>
                <td><?php echo $myrowr[7]?></td>
                <td><?php echo $myrowr[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowr[3];
				$GUsum3=$GUsum3+$myrowr[4];
				$NIEsum3=$NIEsum3+$myrowr[5];
				$MENGsum3=$MENGsum3+$myrowr[6];
				$TONGsum3=$TONGsum3+$myrowr[7];
				$LIsum3=$LIsum3+$myrowr[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月入库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyr=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>入库</td>
				<td><?php echo $myrowyr[0]?></td>
                <td><?php echo $myrowyr[1]?></td>
                <td><?php echo $myrowyr[3]?></td>
                <td><?php echo $myrowyr[4]?></td>
                <td><?php echo $myrowyr[5]?></td>
                <td><?php echo $myrowyr[6]?></td>
                <td><?php echo $myrowyr[7]?></td>
                <td><?php echo $myrowyr[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyr[3];
				$GUsum3=$GUsum3+$myrowyr[4];
				$NIEsum3=$NIEsum3+$myrowyr[5];
				$MENGsum3=$MENGsum3+$myrowyr[6];
				$TONGsum3=$TONGsum3+$myrowyr[7];
				$LIsum3=$LIsum3+$myrowyr[8];
            }
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">当日出库</td>
            </tr>
            <tr>
            	<td>进销存</td>
            	<td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowc=mysqli_fetch_array($resultc)){
				?>
                <tr>
                <td>出库</td>
                <td><?php echo $myrowc[0]?></td>
                <td><?php echo $myrowc[1]?></td>
                <td><?php echo $myrowc[3]?></td>
                <td><?php echo $myrowc[4]?></td>
                <td><?php echo $myrowc[5]?></td>
                <td><?php echo $myrowc[6]?></td>
                <td><?php echo $myrowc[7]?></td>
                <td><?php echo $myrowc[8]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrowc[3];
				$GUsum3=$GUsum3+$myrowc[4];
				$NIEsum3=$NIEsum3+$myrowc[5];
				$MENGsum3=$MENGsum3+$myrowc[6];
				$TONGsum3=$TONGsum3+$myrowc[7];
				$LIsum3=$LIsum3+$myrowc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当月出库累计</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowyc=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>出库</td>
				<td><?php echo $myrowyc[0]?></td>
                <td><?php echo $myrowyc[1]?></td>
                <td><?php echo $myrowyc[3]?></td>
                <td><?php echo $myrowyc[4]?></td>
                <td><?php echo $myrowyc[5]?></td>
                <td><?php echo $myrowyc[6]?></td>
                <td><?php echo $myrowyc[7]?></td>
                <td><?php echo $myrowyc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowyc[3];
				$GUsum3=$GUsum3+$myrowyc[4];
				$NIEsum3=$NIEsum3+$myrowyc[5];
				$MENGsum3=$MENGsum3+$myrowyc[6];
				$TONGsum3=$TONGsum3+$myrowyc[7];
				$LIsum3=$LIsum3+$myrowyc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
			<tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
            <tr>
            	<td>进销存</td>
                <td>原料类别</td>
                <td>原料名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'18',2=>'汇总4.可处理生产尾料',3=>'原料类别',4=>'原料名称',5=>'两大类别',6=>'实物量',7=>'钴',8=>'镍',9=>'锰',10=>'铜',11=>'锂',12=>"  ",13=>"".$sqlr."",14=>"".$sqlyr."",15=>"".$sqlc."",16=>"".$sqlyc."",17=>"".$sqljc."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrowjc=mysqli_fetch_array($resultjc)){
				?>
                <tr>
                <td>结存</td>
				<td><?php echo $myrowjc[0]?></td>
                <td><?php echo $myrowjc[1]?></td>
                <td><?php echo $myrowjc[3]?></td>
                <td><?php echo $myrowjc[4]?></td>
                <td><?php echo $myrowjc[5]?></td>
                <td><?php echo $myrowjc[6]?></td>
                <td><?php echo $myrowjc[7]?></td>
                <td><?php echo $myrowjc[8]?></td>
                </tr>
				<?php
				$SWsum3=$SWsum3+$myrowjc[3];
				$GUsum3=$GUsum3+$myrowjc[4];
				$NIEsum3=$NIEsum3+$myrowjc[5];
				$MENGsum3=$MENGsum3+$myrowjc[6];
				$TONGsum3=$TONGsum3+$myrowjc[7];
				$LIsum3=$LIsum3+$myrowjc[8];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}
	}
	else{
		echo "请重新选择要查询的内容！";
	}
}
else if(isset($_POST['zsbb_xz'])){
	$LB1=$_POST['zsbb_xz'];
	$ti1=$_POST['ti1'];
	$ti2=$_POST['ti2'];
	if($LB1=='srkb'){
		$sql="select LY,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当期入库') from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by LY,name;";
		//echo $sql;
		$sum=8;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sql);
			?>
			<td style="color:#F00; background-color:#FF0;">原料仓库月盘点报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1."~~".$ti2;?></td>
            </tr>
            <tr>
                <td>来源</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'13',2=>'原料仓库月盘点报表',3=>'来源',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>'  ',12=>"".$sql."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB1=='sckb'){
		$sql="select QX,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('当期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by QX,name;";
		//echo $sql;
		$sum=8;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sql);
			?>
			<td style="color:#F00; background-color:#FF0;">原料库十天出库明细报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;">当期出库</td>
            </tr>
            <tr>
                <td>去向</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'13',2=>'原料库十天出库明细报表',3=>'去向',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>'  ',12=>"".$sql."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}
	}
	else if($LB1=='zb'){
		$sql="select r.BLB,r.name,sum(r.SW),ifnull(sum(c.SW),0),(sum(r.SW)-ifnull(sum(c.SW),0)) from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by name,PH,id) as c on r.PH=c.PH and r.name=c.name and r.id=c.id where r.dh_date>='".$ti1."' and r.dh_date<='".$ti2."' group by r.BLB,r.name;";
		//echo $sql;
		$sum=4;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sql);
			?>
			<td style="color:#F00; background-color:#FF0;">周报表</td>
            <tr>
                <td>表类别</td>
                <td>名称</td>
                <td>本期入库</td>
                <td>本期出库</td>
                <td>本期结存</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'9',2=>'周报表',3=>'表类别',4=>'名称',5=>'本期入库',6=>'本期出库',7=>'本期结存',8=>"".$sql."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            </tr>
            <?php
		}
	}
	else{
		echo "请重新选择要查询的内容！";
	}
}
else if(isset($_POST['ybb_xz'])){
	$LB2=$_POST['ybb_xz'];
	$ti1=$_POST['ti1'];
	$ti2=$_POST['ti2'];
	if($LB2=='ypdb'){
		$sqlyr="select BLB,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),KQ,CW from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by BLB,name;";
		$sum=9;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqlyr);
			?>
			<td style="color:#F00; background-color:#FF0;">原料仓库月盘点报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
                <td>表类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
                <td>库区</td>
                <td>储位</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'14',2=>'原料仓库月盘点报表',3=>'表类别',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>'库区',12=>'储位',13=>"".$sqlyr."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                <td><?php echo $myrow[8]?></td>
                <td><?php echo $myrow[9]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB2=='ycrb'){
		$sqljc_q="select r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('上期结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti1."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti1."' group by r.name;";
		$sqlyr="select name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期入库') from rkb where (dh_date>='".$ti1."' and dh_date<='".$ti2."') group by name;";
		$sqlyc="select name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by name;";
		$sqljc_h="select r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti2."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti2."' group by r.name;";
		$sum=7;
		//echo $sqljc_q;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqljc_q); 
			?>
			<td style="color:#F00; background-color:#FF0;">原料库出入库月报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
            	<td>上期结存</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'15',2=>'原料库出入库月报表',3=>'名称',4=>'实物量',5=>'钴',6=>'镍',7=>'锰',8=>'铜',9=>'锂',10=>' ',11=>"".$sqljc_q."",12=>"".$sqlyr."",13=>"".$sqlyc."",14=>"".$sqljc_h."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td>上期结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期入库</td>
            </tr>
			<tr>
            	<td>本期入库</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyr=mysqli_query($connID,$sqlyr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>本期入库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期出库</td>
            </tr>
			<tr>
            	<td>本期出库</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyc=mysqli_query($connID,$sqlyc);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>本期出库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
			<tr>
            	<td>结存</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resulth=mysqli_query($connID,$sqljc_h);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resulth)){
				?>
                <tr>
                <td>结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB2=='ycrhz'){
		$sqljc_q="select r.BLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('上期结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti1."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti1."' group by r.BLB;";
		$sqlyr="select BLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期入库') from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by BLB;";
		$sqlyc="select BLB,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' group by BLB;";
		$sqljc_h="select r.BLB,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti2."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti2."' group by r.BLB;";
		$sum=7;
		//echo $sqljc_q;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqljc_q);
			?>
			<td style="color:#F00; background-color:#FF0;">原料仓库出入库月度汇总表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
            	<td>上期结存</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'15',2=>'原料仓库出入库月度汇总表',3=>'名称',4=>'实物量',5=>'钴',6=>'镍',7=>'锰',8=>'铜',9=>'锂',10=>' ',11=>"".$sqljc_q."",12=>"".$sqlyr."",13=>"".$sqlyc."",14=>"".$sqljc_h."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td>上期结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期入库</td>
            </tr>
			<tr>
            	<td>本期入库</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyr=mysqli_query($connID,$sqlyr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>本期入库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期出库</td>
            </tr>
			<tr>
            	<td>本期出库</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyc=mysqli_query($connID,$sqlyc);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>本期出库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
			<tr>
            	<td>结存</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resulth=mysqli_query($connID,$sqljc_h);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resulth)){
				?>
                <tr>
                <td>结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB2=='bhgpyb_m'){
		$sqljc_q="select r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('上期结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti1."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti1."' and r.BLB='不合格品' group by r.name;";
		$sqlyr="select name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期入库') from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='不合格品' group by name;";
		$sqlyc="select name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='不合格品' group by name;";
		$sqljc_h="select r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti2."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti2."' and r.BLB='不合格品' group by r.name;";
		$sum=7;
		//echo $sqljc_q;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqljc_q);
			?>
			<td style="color:#F00; background-color:#FF0;">不合格品出入库月报表(分名称)</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
            	<td>上期结存</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'15',2=>'不合格品出入库月报表(分名称)',3=>'名称',4=>'实物量',5=>'钴',6=>'镍',7=>'锰',8=>'铜',9=>'锂',10=>' ',11=>"".$sqljc_q."",12=>"".$sqlyr."",13=>"".$sqlyc."",14=>"".$sqljc_h."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td>上期结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期入库</td>
            </tr>
			<tr>
            	<td>本期入库</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyr=mysqli_query($connID,$sqlyr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>本期入库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期出库</td>
            </tr>
			<tr>
            	<td>本期出库</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyc=mysqli_query($connID,$sqlyc);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>本期出库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
			<tr>
            	<td>结存</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resulth=mysqli_query($connID,$sqljc_h);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resulth)){
				?>
                <tr>
                <td>结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[1];
				$GUsum3=$GUsum3+$myrow[2];
				$NIEsum3=$NIEsum3+$myrow[3];
				$MENGsum3=$MENGsum3+$myrow[4];
				$TONGsum3=$TONGsum3+$myrow[5];
				$LIsum3=$LIsum3+$myrow[6];
			}
			?>
            <tr>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB2=='bhgpyb_b'){
		$sqljc_q="select r.LY,r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('上期结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti1."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti1."' and r.BLB='不合格品' group by r.LY,r.name;";
		$sqlyr="select LY,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期入库') from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='不合格品' group by LY,name;";
		$sqlyc="select QX,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='不合格品' group by QX,name;";
		$sqljc_h="select r.LY,r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti2."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti2."' and r.BLB='不合格品' group by r.LY,r.name;";
		$sum=8;
		//echo $sqljc_q;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqljc_q);
			?>
			<td style="color:#F00; background-color:#FF0;">不合格品出入库月报表(分部门)</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
            	<td>上期结存</td>
                <td>制造部</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'16',2=>'不合格品出入库月报表(分部门)',3=>'制造部',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>' ',12=>"".$sqljc_q."",13=>"".$sqlyr."",14=>"".$sqlyc."",15=>"".$sqljc_h."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td>上期结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期入库</td>
            </tr>
			<tr>
            	<td>本期入库</td>
                <td>制造部</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyr=mysqli_query($connID,$sqlyr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>本期入库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期出库</td>
            </tr>
			<tr>
            	<td>本期出库</td>
                <td>制造部</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyc=mysqli_query($connID,$sqlyc);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>本期出库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
			<tr>
            	<td>结存</td>
                <td>制造部</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resulth=mysqli_query($connID,$sqljc_h);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resulth)){
				?>
                <tr>
                <td>结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB2=='dcyb'){
		$sqljc_q="select r.LB1,r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('上期结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB,LB1 from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti1."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti1."' and r.BLB='电池原料及产物' group by r.LB1,r.name;";
		$sqlyr="select LB1,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期入库') from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='电池原料及产物' group by LB1,name;";
		$sqlyc="select LB1,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='电池原料及产物' group by LB1,name;";
		$sqljc_h="select r.LB1,r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB,LB1 from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti2."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti2."' and r.BLB='电池原料及产物' group by r.LB1,r.name;";
		$sum=8;
		//echo $sqljc_q;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqljc_q);
			?>
			<td style="color:#F00; background-color:#FF0;">电池原料及产物月报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
            	<td>上期结存</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'16',2=>'电池原料及产物月报表',3=>'类别',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>' ',12=>"".$sqljc_q."",13=>"".$sqlyr."",14=>"".$sqlyc."",15=>"".$sqljc_h."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td>上期结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期入库</td>
            </tr>
			<tr>
            	<td>本期入库</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyr=mysqli_query($connID,$sqlyr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>本期入库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期出库</td>
            </tr>
			<tr>
            	<td>本期出库</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyc=mysqli_query($connID,$sqlyc);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>本期出库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
			<tr>
            	<td>结存</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resulth=mysqli_query($connID,$sqljc_h);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resulth)){
				?>
                <tr>
                <td>结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
	else if($LB2=='lwryyb'){
		$sqlyr="select month(r.dh_date),r.name,sum(r.GU),sum(r.NIE),r.LY,c.QX from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where year(r.dh_date)>=".date('Y',strtotime($ti2))." and r.BLB='绿钨原料及产物' group by month(r.dh_date),r.name order by r.name;";
		$sum=5;
		//echo $sqlyr;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqlyr);
			?>
			<td style="color:#F00; background-color:#FF0;">绿钨百富溶液出入库月报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
                <td>月份</td>
                <td>名称</td>
                <td>钴</td>
                <td>镍</td>
                <td>来源</td>
                <td>去向</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'10',2=>'绿钨百富溶液出入库月报表',3=>'月份',4=>'名称',5=>'钴',6=>'镍',7=>'来源',8=>'去向',9=>"".$sqlyr."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                </tr>
                <?php
			}
		}	
	}
	else if($LB2=='wlyb'){
		$sqljc_q="select r.BLB,r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('上期结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti1."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti1."' and r.BLB='生产尾料' group by r.name;";
		$sqlyr="select BLB,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期入库') from rkb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='生产尾料' group by BLB,name;";
		$sqlyc="select BLB,name,sum(SW),sum(GU),sum(NIE),sum(MENG),sum(TONG),sum(LI),concat('本期出库') from ckb where dh_date>='".$ti1."' and dh_date<='".$ti2."' and BLB='生产尾料' group by BLB,name;";
		$sqljc_h="select r.BLB,r.name,(sum(r.SW)-ifnull(sum(c.SW),0)),(sum(r.GU)-ifnull(sum(c.GU),0)),(sum(r.NIE)-ifnull(sum(c.NIE),0)),(sum(r.MENG)-ifnull(sum(c.MENG),0)),(sum(r.TONG)-ifnull(sum(c.TONG),0)),(sum(r.LI)-ifnull(sum(c.LI),0)),concat('结存') from (select dh_date,name,PH,id,KQ,sum(BS) as BS,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,BLB,YLLB,LY,LBLB from rkb group by name,PH,id) as r left join (select name,PH,id,car_id,DJ_id,sum(SW) as SW,sum(GU) as GU,sum(NIE) as NIE,sum(MENG) as MENG,sum(TONG) as TONG,sum(LI) as LI,sum(BS) as BS,QX,LB1,LB2 from ckb where dh_date<='".$ti2."' group by name,PH,id) as c on r.name=c.name and r.PH=c.PH and r.id=c.id where r.dh_date<='".$ti2."' and r.BLB='生产尾料' group by r.BLB,r.name;";
		$sum=8;
		//echo $sqljc_q;
		if(mysqli_select_db($connID,$dbName)){
			$result=mysqli_query($connID,$sqljc_q);
			?>
			<td style="color:#F00; background-color:#FF0;">生产尾料出入库月报表</td>
            <tr>
            <td style="color:#F00; background-color:#FF0;"><?php echo $ti1." ~~ ".$ti2;?></td>
            </tr>
            <tr>
            	<td>上期结存</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$arr=array(0=>$sum,1=>'16',2=>'生产尾料出入库月报表',3=>'类别',4=>'名称',5=>'实物量',6=>'钴',7=>'镍',8=>'锰',9=>'铜',10=>'锂',11=>' ',12=>"".$sqljc_q."",13=>"".$sqlyr."",14=>"".$sqlyc."",15=>"".$sqljc_h."");
			$url1='Excel_dy.php?'.http_build_query($arr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($result)){
				?>
                <tr>
                <td>上期结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期入库</td>
            </tr>
			<tr>
            	<td>本期入库</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyr=mysqli_query($connID,$sqlyr);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyr)){
				?>
                <tr>
                <td>本期入库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">本期出库</td>
            </tr>
			<tr>
            	<td>本期出库</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resultyc=mysqli_query($connID,$sqlyc);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resultyc)){
				?>
                <tr>
                <td>本期出库</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <tr>
            <td style="color:#F00; background-color:#FF0;">结存</td>
            </tr>
			<tr>
            	<td>结存</td>
                <td>类别</td>
                <td>名称</td>
                <td>实物量</td>
                <td>钴</td>
                <td>镍</td>
                <td>锰</td>
                <td>铜</td>
                <td>锂</td>
            </tr>
            <?php
			$resulth=mysqli_query($connID,$sqljc_h);
			$SWsum3=0;
			$GUsum3=0;
			$NIEsum3=0;
			$MENGsum3=0;
			$TONGsum3=0;
			$LIsum3=0;
			while($myrow=mysqli_fetch_array($resulth)){
				?>
                <tr>
                <td>结存</td>
                <td><?php echo $myrow[0]?></td>
                <td><?php echo $myrow[1]?></td>
                <td><?php echo $myrow[2]?></td>
                <td><?php echo $myrow[3]?></td>
                <td><?php echo $myrow[4]?></td>
                <td><?php echo $myrow[5]?></td>
                <td><?php echo $myrow[6]?></td>
                <td><?php echo $myrow[7]?></td>
                </tr>
                <?php
				$SWsum3=$SWsum3+$myrow[2];
				$GUsum3=$GUsum3+$myrow[3];
				$NIEsum3=$NIEsum3+$myrow[4];
				$MENGsum3=$MENGsum3+$myrow[5];
				$TONGsum3=$TONGsum3+$myrow[6];
				$LIsum3=$LIsum3+$myrow[7];
			}
			?>
            <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <td><?php echo $SWsum3;?></td>
            <td><?php echo $GUsum3;?></td>
            <td><?php echo $NIEsum3;?></td>
            <td><?php echo $MENGsum3;?></td>
            <td><?php echo $TONGsum3;?></td>
            <td><?php echo $LIsum3;?></td>
            </tr>
            <?php
		}	
	}
}/**/
else{
?>
<tr>
<td align="center">请选择要生成的报表类型！</td>
</tr>
<?php	
}
?>
</div>

<a href="<?php echo $url1;?>"><div class="tz">导出</div></a>

</body>
</html>